package com.yhd.admin.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yhd.admin.bean.User;
import com.yhd.admin.mapper.UserMapper;
import com.yhd.admin.utils.MD5Utils;
import com.yhd.admin.utils.PageUtils;
import com.yhd.admin.utils.QueryWrapper;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public List<User> getUsers(User user, int page, int size) {
		return userMapper.selectUsers(new QueryWrapper<User>(user, new PageUtils(page, size)));
	}

	@Override
	public int getCount(User user) {
		return userMapper.selectCount(user);
	}

	@Override
	public User getUserByUser(User user) {
		return userMapper.selectUserByUser(user);
	}

	@Override
	public void add(User user) {
		//测试使用
		user.setCreator("system");
		//密码默认是“1”，使用md5加密后存储
		user.setPassword(MD5Utils.getMD5String("1"));
		userMapper.add(user);
	}

	@Override
	public void update(User user) {
		userMapper.updateUser(user);
	}

}
